<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
	</head>

	<body style="padding: 0px;">
		<div id="toolbar" style="background: #F4F4F4;border-top:1px solid #95B8E7"></div>
		<div>
			<form id="ff">
				<table style="text-align: left;width: 80%;margin: 0 auto;" cellpadding="5">
					<tr>
						<td width="10%">租户名称</td>
						<td width="23%">
							<input id="input_TENANT_NAME" style="width: 100%;" class="easyui-textbox" name="TENANT_NAME" data-options="disabled:true"></td>
						<td width="10%">库房名称</td>
						<td width="23%">
							<input id="input_STOREHOUSE_NAME" style="width: 100%;" class="easyui-textbox" name="NAME" data-options="disabled:true"></td>
						<td width="10%">商品名称</td>
						<td width="23%">
							<input id="input_GOODS_NAME" style="width: 100%;" class="easyui-textbox" name="GOODS_NAME" data-options="disabled:true"></td>
					</tr>
					<tr>
						<td>
							入库时间
						</td>
						<td>
							<input id="input_IN_DATE" style="width: 100%;" class="easyui-textbox" name="IN_DATE" data-options="disabled:true">
						</td>
						<td>
							规格
						</td>
						<td>
							<input id="input_SPEC" style="width: 100%;" class="easyui-textbox" name="SPEC" data-options="disabled:true">
						</td>
						<td>
							单位
						</td>
						<td>
							<input id="input_UNIT" style="width: 100%;" class="easyui-textbox" name="UNIT" data-options="disabled:true">
						</td>
					</tr>
					<tr>
						<td>
							合伙人1
						</td>
						<td>
							<input type="text" style="width: 100%;" name="PARTNER1" id="input_PARTNER1" class="easyui-textbox" data-options="disabled:true" />
						</td>
						<td>
							合伙人2
						</td>
						<td>
							<input type="text" style="width: 100%;" name="PARTNER2" id="input_PARTNER2" class="easyui-textbox" data-options="disabled:true" />
						</td>
						<td>
							合伙人3
						</td>
						<td>
							<input type="text" style="width: 100%;" name="PARTNER3" id="input_PARTNER3" class="easyui-textbox" data-options="disabled:true" />
						</td>
					</tr>
					<tr>
						<td>入库数量</td>
						<td><input id="input_AMOUNT" style="width: 100%;" class="easyui-textbox" name="AMOUNT" data-options="disabled:true"></td>
						<td>剩余数量</td>
						<td><input id="input_CURR_AMOUNT" style="width: 100%;" class="easyui-textbox" name="CURR_AMOUNT" data-options="disabled:true"></td>
						<td>计费标准</td>
						<td><input id="input_CHARGE_NAME" style="width: 100%;" class="easyui-textbox" name="CHARGE_NAME" data-options="disabled:true"></td>
					</tr>
				</table>
				<div class="easyui-tabs" id="div_tabs" style="width: 100%;margin: 5px;">
					<div title="租赁信息" style="overflow:hidden;height: 300px;">
						<table id="tt">

						</table>
					</div>
					<div title="盘存信息" style="overflow:hidden;height: 300px;">
						<table id="dg">

						</table>
					</div>
				</div>
				<div id="dlg" class="easyui-dialog" closed="true" style="width:560px;height:400px;padding:10px">
					<iframe id="ifrmEdit" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>
				</div>
				<div style="margin-left: 20%;" id="new_footer"></div>
			</form>
			<div id="toolbar_datagrid"></div>
			<div id="toolbar_datagrid2"></div>
		</div>
		<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
		<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../../JS/common.js"></script>
		<script type="text/javascript" src="../../../JS/finance.js"></script>
		<script type="text/javascript" src="../../../JS/FrozenShareFunction/FrozenShare.js"></script>
	</body>
	<script type="text/javascript">
		var id = getID();
		var AddDialog;
		var reData;
		var unit_price = 0;
//		var charge_name = '';
//		var chargetype_id = '';
		var instoredate = '';
		var toolbar = AddToolBar(TOOLBAR_EDITOR);
		$("#toolbar_datagrid").append(toolbar); //datagrid的toolbar
		$("#toolbar_datagrid2").append(toolbar); //datagrid的toolbar

		var newdata = [{
			"icon": "icon-remove",
			"func": "addDetail('remove',-1)",
			"functionname": "移库"
		}, {
			"icon": "icon-warehouseout",
			"func": "addDetail('out',-1)",
			"functionname": "出库"
		}, {
			"icon": "icon-write_off",
			"func": "addDetail('writeoff',-1)",
			"functionname": "冲销帐"
		}, {
			"icon": "icon-information",
			"func": "addDetail('inventory',-1)",
			"functionname": "盘存"
		}];
		var content = AddReceiptsToolBar(0, newdata);
		$("#toolbar").append(content);

		///增加脚注
		addFooter($("#new_footer"));

		//构建datagrid
		GetDetailTable();
		$(document).ready(function(){
		loadRemote();
		});

		//构建数据
		function loadRemote() {
			var _url = RemoteLinkAddress + "/frozen/inorder/findbyid.do?ID=" + 　id;
			getRemoteData(_url);
		}

		function addDetail(type, _id) {
			var title = "";
			var pLocation;
			var DialogWidth = 900;
			var DialogHeight = 400;
			if(type === "remove") {
				DialogWidth = 1000;
				DialogHeight = 330;
				title = "移库";
				pLocation = "UI/FrozenCave/LeasingOperation/LeasingOperationAddRemoveStorage.html?id=" + _id;
				//pLocation = "UI/FrozenCave/LeasingOperation/LeasingOperationAddOutStorage.html?id=" + _id;
			}
			if(type === "out") {
				DialogWidth = 1000;
				DialogHeight = 330;
				title = "出库";
				pLocation = "UI/FrozenCave/LeasingOperation/LeasingOperationAddOutStorage.html?id=" + _id + '&unit_price=' + unit_price + '&instoredate=' + instoredate;
			}
			if(type === "writeoff") {
				DialogWidth = 830;
				DialogHeight = 295;
				title = "冲销帐";
				pLocation = "UI/FrozenCave/LeasingOperation/LeasingOperationAddWriteoffOutStorage.html?id=" + _id;
			}
			if(type === "inventory") {
				DialogWidth = 830;
				DialogHeight = 290;
				title = "盘存";
				pLocation = "UI/FrozenCave/LeasingOperation/LeasingOperationAddInventory.html?id=" + _id;
			}
			$("#ifrmEdit").attr("src", pLocation);
			constructDialog($("#dlg"), title, DialogWidth, DialogHeight);
			AddDialog.dialog('open');
		}

		//弹出到收费界面
		function toChargeUI(id) {
			var DialogWidth = 800;
			var DialogHeight = 330;
			var pLocation = "UI/FrozenCave/TenantCharge/TenantChargeAdd.html?type=out&id=" + id;
			$("#ifrmEdit").attr("src", pLocation);
			constructDialog($("#dlg"), "收费", DialogWidth, DialogHeight);
			AddDialog.dialog('open');
		}

		//编辑
		function editdata() {
			var row = $('#tt').datagrid('getSelected');
			if(!row) {
				$.messager.alert("消息", "请选中数据");
				return;
			}
			var type;
			if(row.TYPE == 0) {
				type = "out";
			}
			if(row.TYPE == 1) {
				type = "remove";
			}
			if(row.TYPE == 2 || row.TYPE == 3) {
				type = "writeoff";
			}
			addDetail(type, row.ID);
		}

		//关闭dialog
		function dialogClose() {
			AddDialog.dialog('close');
		}

		//保存表单的数据，新增记录页面调用
		function ReturnDetailData() {
			return reData;
		}

		//获取数据
		function getRemoteData(_url) {
			$.ajax({
				dataType: 'json',
				type: "get",
				url: _url,
				success: function(result) {
					unit_price = result.UNIT_PRICE;
					instoredate = result.IN_DATE;
					reData = result;
					getFormData(result);
					if(result.rows.length == 0 && result.rows2.length == 0) {
						return;
					}
					var _data = result.rows;
					$("#tt").datagrid("loadData", _data);
					_data = result.rows2;
					$("#dg").datagrid("loadData", _data);
				}
			});
		}

		//构建datagrid
		function GetDetailTable() { //构造datagrid中的数据
			$('#tt').datagrid({
				height: 300,
				width: '100%',
				toolbar: "#toolbar_datagrid",
				collapsible: true, //是否折叠：是
				singleSelect: true, //是否单选：是
				fitColumns: true, //自动调整列：是
				rownumbers: true,
				columns: [
					[{
							field: 'ID',
							title: 'ID',
							width: '0%',
							align: 'center',
						},
						{
							field: 'ORDER_NO',
							title: '编号',
							width: '10%',
							align: 'center',
						},
						{
							field: 'CREATE_TIME',
							title: '操作时间',
							width: '10%',
							align: 'center',
						},
						{
							field: 'CHARGER',
							title: '缴费人',
							width: '10%',
							align: 'center',
							//							formatter: function(value, row, index) {
							//								if(row.TYPE == 1) {
							//									return "无";
							//								} else {
							//									return row.CHARGER;
							//								}
							//							}
						}, {
							field: 'AMOUNT',
							title: '数量',
							width: '20%',
							align: 'center',
						}, {
							field: 'TYPE',
							title: '类型',
							width: '20%',
							align: 'center',
							formatter: function(value, row, index) {
								switch(value) {
									case "0":
										return "出库";
										break;
									case "1":
										return "移库";
										break;
									case "2":
										return "冲帐";
										break;
									case "3":
										return "销账";
										break;
								}
							}
						},
						{
							field: 'ISCHARGE',
							title: '出库收费',
							width: '20%',
							align: 'center',
							formatter: function(value, row, index) {
								return IsChargeState(value);
							}
						},
					]
				],
				onDblClickRow: function(index, row) {
					var type;
					if(row.TYPE == 0) {
						type = "out";
					}
					if(row.TYPE == 1) {
						type = "out"; //移动也作为出库来处理
					}
					if(row.TYPE == 2 || row.TYPE == 3) {
						type = "writeoff";
					}
					addDetail(type, row.ID);
				}
			});
			$("#tt").datagrid("hideColumn", 'ID');

			$('#dg').datagrid({
				height: 300,
				width: '100%',
				toolbar: "#toolbar_datagrid2",
				collapsible: true, //是否折叠：是
				singleSelect: true, //是否单选：是
				fitColumns: true, //自动调整列：是
				rownumbers: true,
				columns: [
					[{
							field: 'ID',
							title: 'ID',
							width: '0%',
							align: 'center',
						},
						{
							field: 'ORDER_NO',
							title: '编号',
							width: '10%',
							align: 'center',
						},
						{
							field: 'INVENTORY_DATE',
							title: '盘存日期',
							width: '19%',
							align: 'center',
						}, {
							field: 'OPERATOR',
							title: '盘存人',
							width: '10%',
							align: 'center',
						}, {
							field: 'BOOKSTOCK',
							title: '账面库存量',
							width: '20%',
							align: 'center',
						}, {
							field: 'REALSTOCK',
							title: '盘点库存量',
							width: '20%',
							align: 'center',
						}, {
							field: 'ISVERIFY',
							title: '审核状态',
							width: '15%',
							align: 'center',
							formatter: function(value, row, index) {
								return verifyStatus(value, false);
							}
						}
					]
				],
				onDblClickRow: function(index, row) {
					addDetail("inventory", row.ID);
				}
			});
			$("#dg").datagrid("hideColumn", 'ID');
		}
		function dialogClose() {
			AddDialog.dialog('close');
		}
	</script>

</html>